/*
 * @lc app=leetcode.cn id=167 lang=javascript
 *
 * [167] 两数之和 II - 输入有序数组
 */

// @lc code=start
/**
 * @param {number[]} numbers
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function (numbers, target) {
  const n = numbers.length;
  let i = 0;
  let j = n - 1;
  // 有序数组的双指针天然适合双向指针，而不是快满指针
  let sum;
  while (i < j) {
    sum = numbers[i] + numbers[j];
    if (sum === target) return [i + 1, j + 1];
    if (sum > target) j--;
    else i++;
  }
  return [-1, -1];
};
// @lc code=end
